/**
 * FileName: SeckillCommodityController
 *
 * @author: 阿张
 * Date:     2021/2/26 14:35
 */
package com.qx.controller;

import com.qx.service.SeckillCommodityService;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import result.Result;
import result.ResultFactory;

import javax.annotation.Resource;
import java.util.Objects;

@RestController
@RequestMapping("app/seckillCommodity")
public class SeckillCommodityController {

    @Resource
    private SeckillCommodityService seckillCommodityService;

    @RequestMapping(value = "/selectByDeployId/{deploy_Id}",method = RequestMethod.POST)
    public Result selectByDeployId(@PathVariable("deploy_Id")Integer deploy_Id){
        if (Objects.nonNull(deploy_Id)){
            return ResultFactory.buildSuccessResult(seckillCommodityService.listById(deploy_Id));
        }
        return ResultFactory.buildFailResult("发生错误");
    }

    @RequestMapping(value = "/getRemainingInventory/{commodityId}",method = RequestMethod.POST)
    public Result getRemainingInventory(@PathVariable("commodityId") Integer commodityId){
        if (Objects.nonNull(commodityId)){
            return ResultFactory.buildSuccessResult(seckillCommodityService.selectByCommodityId(commodityId));
        }
        return ResultFactory.buildFailResult("发生错误");
    }

    @RequestMapping(value = "getSpikeTime",method = RequestMethod.GET)
    public Result getSpikeTime(){
        return ResultFactory.buildSuccessResult(seckillCommodityService.getSpikeTime());
    }
}
